<style scoped lang="scss">
  .mapWrapper {
    display: flex;
    height: 32px;
    justify-content: flex-start;
    align-items: center;
    border-radius: 4px;
    background-color: #f7f7f7;
    margin:2px 0;
  }
  .labelWrapper {
    display: flex;
    height:32px;
    width:150px;
    justify-content: flex-end;
    align-items: center;
    padding: 0 5px;
    border: 1px solid #dcdee2;
    border-right:none;
    border-radius: 4px 0px 0px 4px;
    font-size: 14px;
    background-color: #f7f7f7;
  }
  .labelTip {
    height:100%;
  }
  .editor {
    height:100%;
    flex:1 1 auto;
    border: none;
    padding:0;
  }
  .mark {
    width:5px;
    height:32px;
    background-color: #2d8cf0;
    border-color: #2d8cf0;
    margin-right:2px;
    opacity: 0.6;
  }
  .action {
    width:20px;
    margin-right: 5px;
    margin-left:5px;
    cursor: pointer;
  }
</style>
<template>
  <div class="mapWrapper">
    <div class="mark"></div>
    <Tooltip class="labelTip" placement="top" :content="tip" :disabled="!tip" transfer>
      <div class="labelWrapper" :style="labelStyle"><span>{{label}}</span></div>
    </Tooltip>
    <starTemplateCell class="editor" v-model="editValue" :config="config" @change="change"></starTemplateCell>
    <div v-if="addField" class="action" @click="$emit('addField')">+</div>
    <div v-if="removeField" class="action" @click="$emit('removeField')">-</div>
  </div>
</template>

<script>
export default {
  name: "starTemplateField",
  components: {},
  model: {
    prop: 'value',
    event: 'change'
  },
  data() {
    return {
      editValue:null
    }
  },
  props: {
    value:{
      default:()=>{
        return null;
      }
    },
    labelStyle: {
      default: () => {
        return {};
      }
    },
    config: {
      default: () => {
        return {};
      }
    },
    label: {
      default: () => {
        return '';
      }
    },
    tip: {
      default: () => {
        return null;
      }
    },
    addField: {
      default: () => {
        return false;
      }
    },
    removeField: {
      default: () => {
        return false;
      }
    },
  },
  computed: {},
  beforeMount() {

  },
  mounted() {
    this.editValue=this.value;
  },
  watch: {
    value:function(newVal){
      this.editValue=newVal;
    }
  },
  methods: {
    change(){
      this.$emit('change',this.editValue);

    }
  }
}
</script>
    